package com.quark.framework.database;

import java.util.HashMap;
import java.util.Map;

public class QuarkDBTableInfo {
	enum QUARKDB_COLUMN_INFO
	{
		COLUMN_PRIMARY_KEY,
		COLUMN_EXPORT_KEY,
		COLUMN_EXPORT_TO_TABLE,
		COLUMN_IMPORT_KEY,
		COLUMN_IMPORT_FROM_TABLE,
	}
	public String tableName = "";
	public Map<String, Map<QUARKDB_COLUMN_INFO, String>> columnInfo = new HashMap<String, Map<QUARKDB_COLUMN_INFO, String>>();
	
	public boolean isForeignKey(String key)
	{
		key = key.toUpperCase();
		return columnInfo.containsKey(key);
	}
	
	public boolean isPrimaryKey(String key)
	{
		if(!columnInfo.containsKey(key))
			return false;
		String value = columnInfo.get(key).get(QUARKDB_COLUMN_INFO.COLUMN_PRIMARY_KEY);
		if(value != null)
			return value.equals("TRUE");
		return false;
	}
	
	public String[] getForeignKeyInfo(String key)
	{
		key = key.toUpperCase();
		Map<QUARKDB_COLUMN_INFO, String> col = columnInfo.get(key);		
		if(col == null)
			return null;
		String[] ret = new String[2];
		ret[0] = col.get(QUARKDB_COLUMN_INFO.COLUMN_EXPORT_KEY);
		ret[1] = col.get(QUARKDB_COLUMN_INFO.COLUMN_EXPORT_TO_TABLE);
		return ret;
	}
	
	protected void setProperty(String key, QUARKDB_COLUMN_INFO type, String value)
	{
		key = key.toUpperCase();
		Map<QUARKDB_COLUMN_INFO, String> col = columnInfo.get(key);
		if(col == null)
		{
			col = new HashMap<QUARKDB_COLUMN_INFO, String>();
			columnInfo.put(key, col);
		}
		col.put(type, value);
	}
	
	
	
	
}
